<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>
		<div style="width: 100%; display:flex;flex-flow:row;margin: 30px 0;align-items: center;justify-items: center; ">
			
			
			
			<div  style="margin-left: 100px;">修改人：</div>
			<el-select v-model="fixer"  size="small" clearable filterable placeholder="请选择"
				 @change="show_pw">
				<el-option v-for="item in worker_list" :key="item.label" :label="item.label" :value="item.value">
				</el-option>
			</el-select>
			
		
			
			<el-button style="margin-left: 5%;"  size="mini" type="success" @click="refleash()">刷新
			</el-button>
			
			
			
			
		</div>	
				
		<div style="width: 100%; display:flex;flex-flow:row;margin: 30px 0;align-items: center;justify-items: center; ">
			<div  :style="'display:flex;flex-flow:row; margin:0 40px 0px 40px;  width: 45%;  '">
				<div  style="margin-left: 100px;">EVENT_ID：</div>
				<el-select v-model="event_choice"  size="small" clearable filterable placeholder="请选择"
					@change="get_choice_event()">
					<el-option v-for="item in event_options" :key="item.label" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
				
				<el-button style="margin-left: 5%;"  size="mini" type="primary" @click="addnew_event()">新增
				</el-button>
			</div>
			<div  :style="'display:flex;flex-flow:row; margin:0 40px 0px 40px;  width: 45%;  '">
			
				<div  style="margin-left: 100px;">TRANSACT_ID：</div>
				<el-select v-model="transact_choice"  size="small" clearable filterable placeholder="请选择"
					@change="get_choice_transact()">
					<el-option v-for="item in transact_options" :key="item.label" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
				
				<el-button style="margin-left: 5%;"  size="mini" type="primary" @click="addnew_transact()">新增
				</el-button>
				
			</div>
		</div>	
		

		<div style="display:flex;flex-flow:row; width: 100%;">
			

			<div  :style="'display:flex;flex-flow:column; margin:0 40px 100px 40px; background-color: white; width: 45%; font-size: 14px;  '">

				<div class="input_item">
					<span class="input_item_title" >e_id：</span>
					<el-input v-model="event_data['e_id']" disabled size="small" style="width: 300px;"@change=" change_cell('e_id','event')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">e_name：</span>
					<el-input v-model="event_data['e_name']" size="small" style="width: 300px;"@change=" change_cell('e_name','event')">
					</el-input>
				
				</div>
				
				
				<div class="input_item">
					<span class="input_item_title">e_writer：</span>
					<el-select v-model="event_data['e_writer']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('e_writer','event')">
						<el-option v-for="item in worker_list" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_chinese_name：</span>
					<el-input v-model="event_data['e_chinese_name']" size="small" style="width: 300px;"@change=" change_cell('e_chinese_name','event')">
					</el-input>
				
				</div>
				
				
				
				<div class="input_item">
					<span class="input_item_title">e_can_restart：</span>
					<el-select v-model="event_data['e_can_restart']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('e_can_restart','event')">
						<el-option v-for="item in use_options" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				
				<div class="input_item">
					<span class="input_item_title">e_type：</span>
					<el-select v-model="event_data['e_type']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('e_type','event')">
						<el-option v-for="item in e_typelist" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				
				
				
				<div class="input_item">
					<span class="input_item_title">e_start_time：</span>
					<el-input v-model="event_data['e_start_time']" size="small" style="width: 300px;"@change=" change_cell('e_start_time','event')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">e_end_time：</span>
					<el-input v-model="event_data['e_end_time']" size="small" style="width: 300px;"@change=" change_cell('e_end_time','event')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">e_week_day：</span>
					<el-input v-model="event_data['e_week_day']" size="small" style="width: 300px;"@change=" 
					change_cell('e_week_day','event')">
					</el-input>
				
				</div>
				
				<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
					<span class="input_item_title">e_useflag：</span>
					<el-select v-model="event_data['e_useflag']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('e_useflag','event')">
						<el-option v-for="item in use_options" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				</div>
				<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
					<span class="input_item_title">e_cmd_server：</span>
					<el-input v-model="event_data['e_cmd_server']" size="small" style="width: 300px;" 
					 :rows="2" @change=" change_cell('e_cmd_server','event')">
					</el-input>
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_cmd_path：</span>
					<el-input v-model="event_data['e_cmd_path']" size="small" style="width: 500px;" type="textarea" 
					 :rows="2" @change=" change_cell('e_cmd_path','event')">
					</el-input>
				
				</div>
				<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
					<span class="input_item_title">e_log_server：</span>
					<el-input v-model="event_data['e_log_server']" size="small" style="width: 300px;"
					 :rows="2" @change=" change_cell('e_log_server','event')">
					</el-input>
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_log_path：</span>
					<el-input v-model="event_data['e_log_path']" size="small" style="width: 500px;" type="textarea"  
					:rows="2" @change=" change_cell('e_log_path','event')">
					</el-input>
				
				</div>
				
				<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
					<span class="input_item_title">e_error_server：</span>
					<el-input v-model="event_data['e_error_server']" size="small" style="width: 300px;" 
					 :rows="2" @change=" change_cell('e_error_server','event')">
					</el-input>
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_error_path：</span>
					<el-input v-model="event_data['e_error_path']" size="small" style="width: 500px;" type="textarea" 
					 :rows="2" @change=" change_cell('e_error_path','event')">
					</el-input>
				
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_note：</span>
					<el-input v-model="event_data['e_note']"   size="small" style="width: 300px;"
					@change=" change_cell('e_note','event')">
					</el-input>
				
				</div>
				
				<div class="input_item">
					<span class="input_item_title">e_input_type：</span>
					<el-input v-model="event_data['e_input_type']"  disabled size="small" style="width: 300px;"
					@change=" change_cell('e_input_type','event')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">e_last_run_date：</span>
					<el-input v-model="event_data['e_last_run_date']"  disabled size="small" style="width: 300px;"
					@change=" change_cell('e_last_run_date','event')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">e_last_run_status：</span>
					<el-select v-model="event_data['e_last_run_status']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('e_last_run_status','event')">
						<el-option v-for="item in status_opotion" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				
				
				
				
				<div class="input_item">
					<span class="input_item_title">updatetime：{{event_data['updatetime']}}</span>
					
				
				</div>
				
				
			
				
				
				<div style="width: 100%;margin: 30px;text-align:center; ">
					
					<el-button style="margin: 30px;" size="mini" type="warning" @click="handleDelete_event()">删除</el-button>
				</div>		
				

			</div>
	
			
			<div  :style="'display:flex;flex-flow:column; margin:0 40px 100px 40px; background-color: white; width: 40%; font-size: 14px;  overflow-y: scroll; '  ">
			
				
				<div class="input_item">
					<span class="input_item_title" >t_id：</span>
					<el-input v-model="transact_data['t_id']" disabled size="small" style="width: 300px;" 
					@change=" change_cell('t_id','transact')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">t_name：</span>
					<el-input v-model="transact_data['t_name']" size="small" style="width: 300px;"@change="
					 change_cell('t_name','transact')">
					</el-input>
				
				</div>
				
				
				<div class="input_item">
					<span class="input_item_title">t_writer：</span>
					<el-select v-model="transact_data['t_writer']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('t_writer','transact')">
						<el-option v-for="item in worker_list" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				<div class="input_item">
					<span class="input_item_title">t_chinese_name：</span>
					<el-input v-model="transact_data['t_chinese_name']" size="small" style="width: 300px;"
					@change="change_cell('t_chinese_name','transact')">
					</el-input>
				
				</div>
				
				
				
				<div class="input_item">
					<span class="input_item_title">t_useflag：</span>
					<el-select v-model="transact_data['t_useflag']" size="small" style="width: 300px;" collapse-tags
						placeholder="请选择" @change=" change_cell('t_useflag','transact')">
						<el-option v-for="item in use_options" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				
				</div>
				
				
			
				<div class="input_item">
					<span class="input_item_title">t_step_num：</span>
					<el-input v-model="transact_data['t_step_num']" size="small" style="width: 300px;"@change="
					 change_cell('t_step_num','transact')">
					</el-input>
				
				</div>
				<div class="input_item">
					<span class="input_item_title">t_step_flow：</span>
					<el-input v-model="transact_data['t_step_flow']" size="small" style="width: 300px;"@change="
					 change_cell('t_step_flow','transact')">
					</el-input>
				
				</div>
			
				
				<div class="input_item">
					<span class="input_item_title">t_note：</span>
					<el-input v-model="transact_data['t_note']" size="small" style="width: 500px;" type="textarea"
					  :rows="2" @change=" change_cell('t_note','transact')">
					</el-input>
				
				</div>
			
				<div class="input_item">
					<span class="input_item_title">updatetime：{{transact_data['updatetime']}}</span>
					
				
				</div>
				
				
				<div style="width: 100%;margin: 30px;text-align:center; ">
					
					<el-button style="margin: 30px;" size="mini" type="warning" @click="handleDelete_transact()">删除</el-button>
				</div>	
				
			</div>
	
			

		</div>
		
	


	</div>
</template>





<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				visible:false,
				event_choice:'',
				transact_choice:'',
				accountchoice: '',
				accountcompare: '',
				event_options:[],
				transact_options:[],
				event_data:{},
				transact_data:{},
				old_event_data:{},
				fixer:'none',
				max_event_id:'',
				max_transact_id:'',
				status_opotion:[
					{value: 'success',label: 'success'	},
					{value: 'running',label: 'running'	},	
					{value: 'waiting',label: 'waiting'	},	
					{value: 'error',label: 'error'	},
				],
				e_typelist:[
					{
						value: 'exe',
						label: 'exe'
					},
					{
						value: 'alert',
						label: 'alert'
					},
					
					
				],
				fixer_options: [{
						value: 'humu',
						label: 'humu'
					},
					{
						value: 'xiupeng',
						label: 'xiupeng'
					},
					{
						value: 'xiongkai',
						label: 'xiongkai'
					},
				],
				use_options:[
					{
						value: 'yes',
						label: 'yes'
					},
					{
						value: 'no',
						label: 'no'
					},
					
				],

				
				
				
				
				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				useflag:true,
				dataname: "",

			}
		},
		components: {
			headTop,
		},
		created() {
			
			this.get_event_list();
			this.get_transcat_list();
						
		},
		
		
		activated() {

			// console.log("当前登入用户2", this.$store.state.adminInfo.name);
			// if (this.tradesysPermission_list.indexOf(this.$store.state.adminInfo.permission) == -1) {
			// 	console.log(this.$store.state.adminInfo.name, this.$store.state.adminInfo.permission)
			// 	this.$message({
			// 		type: 'error',
			// 		message: '没有权限',
			// 	});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},

		computed: {
		},
		watch:{
			filterText(val) {
					this.$refs.tree.filter(val);
				  },
			$route() {
				console.log(this.$route.meta)
				if (this.$route.query.e_id != null) {
					
					
					var that = this;
					// that.stock_id=this.$route.query.stock_id;
					that.event_choice=this.$route.query.e_id;
				
					this.get_choice_event()
					// this.get_feature_json()
					
				}
			}
		},
		methods: {
		   
			refleash() {

				this.get_event_list();
				this.get_transcat_list();
			
				
			},
			show_pw() {
				
				var that=this
				if (this.fixer=='none' ){
					return
				}
				
				setTimeout(function() {that.fixer='none' ;}, 10 * 60 *1000);
				
				var that = this;
				this.$prompt('请输入密码', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',inputType: 'password',
					inputType: 'password',
				}).then(({
					value
				}) => {
					if (value == '621890') {
						this.$message({
							type: 'success',
							message: '密码正确:'
						});
						
					} else {
						this.$message({
							type: 'error',
							message: '密码出错'
						});
						that.fixer='none'
					}
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消输入'
					});
					that.fixer='none'
				});
			},
			
			get_transcat_list() {
				var that = this;
				
				let sql = " select *,date_format(e_updatetime,'%Y-%m-%d') as updatetime from workflow_event order by e_id_num desc ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					//console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.max_event_id=response.data[0]['e_id_num']
						that.event_options = []
						for (var i = 0; i < response.data.length; i++) {
					
							let char = {
								value: response.data[i]['e_id'],
								label: response.data[i]['e_id']+'/'+response.data[i]['e_name'],
							};
						
							that.event_options.push(char);
						}
						
					} else {
						console.log(response.data.statusCode);
					}
				})
			},
			
			handleDelete_event() {
			
				
				// this.exchange_arrange=row
				var that = this;
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					this.refleash()
					return
				}
				this.$confirm('删除数据'+this.event_data['e_id']+', 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',inputType: 'password',
					type: 'warning'
				}).then(() => {
			
			
					let sql2 = "delete from `workflow_event`  WHERE `e_id`='" + this.event_data['e_id'] + "';"
			
					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {
							this.$message({
								message: '删除完成',
								type: 'success'
							});
							that.transact_event=''
							that.event_data=[]
							this.get_choice_event()
						} else {
							return
							console.log(response.data.statusCode);
						}
					})
			
			
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消删除'
					});
				});
			},
			handleDelete_transact() {
			
				
				// this.exchange_arrange=row
				var that = this;
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					this.refleash()
					return
				}
				this.$confirm('删除数据'+this.transact_data['t_id']+', 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',inputType: 'password',
					type: 'warning'
				}).then(() => {
			
			
					let sql2 = "delete from `workflow_transact`  WHERE `t_id`='" + this.transact_data['t_id'] + "';"
			
					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {
							this.$message({
								message: '删除完成',
								type: 'success'
							});
							that.transact_choice=''
							that.transact_data=[]
							this.get_choice_transact()
						} else {
							return
							console.log(response.data.statusCode);
						}
					})
			
			
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消删除'
					});
				});
			},
			get_event_list() {
				var that = this;
				
				let sql = " select *,date_format(t_updatetime,'%Y-%m-%d') as updatetime from workflow_transact order by t_id_num desc ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					//console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.max_transact_id=response.data[0]['t_id_num']
						that.transact_options = []
						for (var i = 0; i < response.data.length; i++) {
					
							let char = {
								value: response.data[i]['t_id'],
								label: response.data[i]['t_id']+'/'+response.data[i]['t_name'],
							};
						
							that.transact_options.push(char);
						}
						
					} else {
						console.log(response.data.statusCode);
					}
				})
			},
			change_cell(column,model) {
				// console.log(scope.$index)
				var that = this
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					this.refleash()
					return
				}
				
				if (!this.event_data['e_id'] && model=='event'){
					this.$message({
						message: '未选择EVENT',
						type: 'error'
					});
					this.refleash()
					return
				}
				if (!this.transact_data['t_id'] && model=='transact'){
					this.$message({
						message: '未选择transact',
						type: 'error'
					});
					this.refleash()
					return
				}
				let sql2=''
				if ( model=='event'){
					
					
					
					sql2 = "UPDATE `workflow_event` SET `"+column+"` = '" + this.event_data[column] + "' \
					WHERE `e_id` = '" + this.event_data['e_id'] + "';"
					if ( column=='e_last_run_status'){
						that.event_data['e_input_type']='man'
						sql2 = "UPDATE `workflow_event` SET e_input_type='man' ,`"+column+"` = '" + this.event_data[column] + "' \
						WHERE `e_id` = '" + this.event_data['e_id'] + "';"		
								
					}
						
						
						
				}
				if ( model=='transact'){
					
					sql2 = "UPDATE `workflow_transact` SET `"+column+"` = '" + this.transact_data[column] + "' \
					WHERE `t_id` = '" + this.transact_data['t_id'] + "';"
					
				}
				
				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						this.$message({
							message: '更新',
							type: 'success'
						});
						// this.get_exchange_arrange()
					} else {
						return
						console.log(response.data.statusCode);
					}
				})
				
			
			
				
			
			
			},
			
			check_config() {
				var that = this;
				//console.log(that.account_choice)
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					return
				}
				if( this.event_data['program_code'].length<3){
					this.$message({
						message: this.event_data['program_code'],
						type: 'error'
					});
					return
				}
				
				
				that.$axios.post(that.lpapi2, "form=check_config" +"&program_code="+this.event_data['program_code']).then(response => {
				
					 //console.log(response.data, 'hdfdata');
					if (response.status = 200) {
						this.$message({
							message: response.data,
							type: 'success'
						});
						
					} else {
						console.log(response.data.statusCode);
					}
				})
			
			},
			
			addnew_event() {
				var that = this
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					return
				}
				// let new_id=this.event_incre(that.max_event_id)
			    let new_id='e'+ (that.max_event_id+1)
				let new_id_num=that.max_event_id+1
				let sql2 = "INSERT IGNORE INTO `workflow_event`  (`e_id`,`e_id_num`,`e_week_day`) VALUES ('" + new_id +"','"+ new_id_num +"','1,2,3,4,5'   );"
			
				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						that.$message({
							message: '新增完成',
							type: 'success'
						});
						
						that.event_choice=new_id
						that.refleash();
						that.get_choice_event();
					} else {
						this.$message({
							message: '新增失败',
							type: 'error'
						});
						console.log(response.data);
					}
				})
			
			
			},
			
			addnew_transact() {
				var that = this
				if (this.fixer=='none' ){
					this.$message({
						message: '未选择修改人',
						type: 'error'
					});
					return
				}
				// let new_id=this.transact_incre(that.max_transact_id)
			    let new_id='t'+ (that.max_transact_id+1)
				let new_id_num=that.max_transact_id+1
				let sql2 = "INSERT IGNORE INTO `workflow_transact`  (`t_id`,`t_id_num`) VALUES ('" + new_id +"', '" + new_id_num +"');"
			
				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						that.$message({
							message: '新增完成',
							type: 'success'
						});
						
						that.transact_choice=new_id
						that.refleash();
						that.get_choice_transact();
					} else {
						this.$message({
							message: '新增失败',
							type: 'error'
						});
						console.log(response.data);
					}
				})
			
			
			},
			
			
			
			get_choice_event() {
				var that = this;
				// console.log(that.lpapi2)
		    	that.event_data = {};
				let sql =
					"select *,date_format(e_updatetime,'%Y-%m-%d') as updatetime from workflow_event  where e_id='"+ this.event_choice+"' ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
			
					console.log(response, 'workflow_event')
				
					if (response.status = 200) {
						that.event_data = response.data[0];
						
						
					} else {
						console.log(that.event_data);
					}
				})
			
			
			},
			
			get_choice_transact() {
				var that = this;
				// console.log(that.lpapi2)
				that.transact_data = {};
				let sql =
					"select *,date_format(t_updatetime,'%Y-%m-%d') as updatetime from workflow_transact  where t_id='"+ this.transact_choice+"' ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
			
					console.log(response, 'workflow_transact')
				
					if (response.status = 200) {
						that.transact_data = response.data[0];
						
						
					} else {
						console.log(that.transact_data);
					}
				})
			
			
			},
					



		},
	}
</script>












<style>
	.my-badge {
	        color: #fff;
	        background: #99a9bf;
			margin-left: 10px;
	        padding: 3px 8px ;
	        font-size: 10px;
	        /* line-height: 12px; */
	        border-radius: 20px;
	        text-align: center;
	    }
	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.input_item{
		display: flex;
		align-items: center;
		padding-top: 20px; 
		justify-content:center;
		
	}
	.input_item_title{
		
		width: 250px; 
		padding-right: 5px;
		text-align: right;
		/* background-color: red; */
	}
	.show_item{
		width: 100%;
		overflow:auto;
		display: flex;
		align-items: center;
		padding-top: 33px; 
		padding-left: 30px; 
		justify-content:flex-start;
		/* background-color: red */
	}
</style>
